<template>
  <rm-layout-top splitcolor="white" :splitwidth=5 :fixsize=35 :canDrag=false>
      <template v-slot:fix>
          <div style="height:35px;border:1px solid #CCC;padding:3px">
              <el-row>
                  <el-col :span="12">
                      <div class="grid-content bg-purple"> <span class="remind_class">开瓶试剂过期提醒，以下开瓶试剂已过期</span></div>
                  </el-col>
                  <el-col :span="12">
                      <div style="line-height:25px">
                          <el-button style="width:72px" @click.native="btnAbandon">遗弃</el-button>
                          <el-button style="width:72px" @click.native="btnRefresh">刷新</el-button>
                          <!-- <el-button @click.native="btnLookExeRecord">查看执行记录</el-button> -->
                          <el-button style="width:72px" @click.native="btnClose">退出</el-button>
                      </div>
                  </el-col>
              </el-row>
          </div>
      </template>
      <div style="height:100%">
          <vxe-table show-overflow ref="xTable" :data.sync="list" height="auto" width="100%" border size="mini" :select-config="{ reserve: true }" show-header-overflow highlight-current-row resizable header-align="center" :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false }" key="1" :row-class-name="rowclassname" class="mytable-style" @current-change="currentChangeEvent" :loading="loading">
              <vxe-table-column field="warehousename" title="仓库" width="70" sortable align="center"></vxe-table-column>
              <vxe-table-column field="labgroupname" title="工作组" width="70" sortable></vxe-table-column>
              <vxe-table-column field="singlebarcode" title="单品条码" width="100" sortable align="center"></vxe-table-column>
              <vxe-table-column field="itemname" title="商品名称" width="130" sortable></vxe-table-column>
              <vxe-table-column field="lotno" title="批号" width="70" sortable header-align="center"></vxe-table-column>
              <vxe-table-column field="expirydate" title="有效期" width="120" sortable align="center"></vxe-table-column>
              <vxe-table-column field="qty" title="数量" width="50" sortable align="center"></vxe-table-column>
              <vxe-table-column field="unit" title="单位" width="70" sortable align="center"></vxe-table-column>
              <vxe-table-column field="itemcode" title="商品代码" width="70" sortable></vxe-table-column>
              <vxe-table-column field="itemlotnoid" title="批次" width="60" sortable align="center"></vxe-table-column>
              <vxe-table-column field="itemid" title="商品ID" width="60" sortable align="center"></vxe-table-column>
          </vxe-table>
      </div>
  </rm-layout-top>
</template>

<script type="text/javascript">
export default {
  props: {
      tabledata: { type: Array },
      params: { type: Object },
  },
  name: "rm_invuseexpirydtwarn",
  data() {
      return {
          useexpirydata: this.tabledata,
          useObj: { formobj: {}, tableobj: [], usekey: 0 },
          loading: false,
      };
  },
  created() {},
  computed: {
      list() {
          return this.useexpirydata;
      },
  },
  watch: {},
  mounted() {
      //console.log("useexpirydata", this.useexpirydata);
      setTimeout(() => {
          if (this.$refs.xTable && this.tabledata.length > 0) {
              this.selectRow(this.tabledata[0]);
          } else {
              this.selectRow("");
          }
      }, 10);
  },
  methods: {
      //选中行并赋值
      selectRow(row) {
          if (!!row) {
              if (this.$refs.xTable) this.$refs.xTable.setCurrentRow(row);
          } else {
              if (this.$refs.xTable) this.$refs.xTable.setCurrentRow(null);
          }
      },
      //获取自动提醒弹窗的选中行
      currentChangeEvent({ row, column }) {
          if (row) {
              this.selectRow(row);
          } else {
              this.selectRow("");
          }
      },
      //自动提醒弹窗列表的颜色
      rowclassname({ row, column }) {
          return "row-pink";
      },
      //执行维护计划查询
      btnAbandon() {
          let data = this.$refs.xTable.getCurrentRow();
          this.$confirm("开瓶试剂:[" + data.itemname + "]已过期，您是否现在就要遗弃,遗弃后过期提醒不再包含该试剂？", "提示", { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning" })
              .then(() => {
                  this.abandon(data);
              })
              .catch(() => {
                  //取消
              });
      },
      abandon(data) {
          if (!!data) {
              this.$tool
                  .request({
                      url: "ucent/invalert",
                      method: "post",
                      data: {
                          action: "useflagConfirm",
                          itemid: data.itemid,
                          singlebarcode: data.singlebarcode,
                      },
                  })
                  .then((res) => {
                      if (res.errcode == "1") {
                          this.$alert("已遗弃，请做好仓库中对应试剂的遗弃工作！", "提示");
                      } else {
                          this.$alert(res.errmsg, "提示");
                      }

                      this.btnRefresh();
                  })
                  .catch((e) => {
                      this.$alert(e, "提示");
                  });
          } else {
              this.$alert("请选择需要遗弃的数据！", "提示");
          }
      },
      //刷新
      btnRefresh() {
          this.loading = true;
          this.$tool
              .request({
                  url: "ucent/alertmsg",
                  method: "post",
                  data: {
                      params: this.params.paramlist,
                  },
              })
              .then((res) => {
                  this.useexpirydata = res.data;
                  if (this.$refs.xTable && this.list.length > 0) {
                      this.selectRow(this.list[0]);
                  } else {
                      this.selectRow("");
                  }
                  this.loading = false;
              })
              .catch((e) => {
                  this.$alert(e, "提示");
                  this.loading = false;
              });
      },
      //退出
      btnClose() {
          this.$emit("change", "close");
      },
  },
};
</Script>

<style scoped>
.remind_class {
  color: rgb(236, 11, 11);
  font-size: 18px;
}
::v-deep .mytable-style .vxe-body--row.row-pink {
  background-color: pink;
  color: rgb(8, 8, 8);
}
</style>